package old;

import java.io.IOException;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modeles.News;
import robot.PMF;


public class AjouterNewsServlet extends HttpServlet {

	private static final long serialVersionUID = -2502133846514921463L;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)	throws IOException {
		resp.setContentType("text/plain");
		String contenu = req.getParameter("contenu");
		String nomDeLaNews = req.getParameter("nomDeLaNews");
		PersistenceManager pm = PMF.get().getPersistenceManager();
		News news = null;
		try{
			news = (News) pm.getObjectById(nomDeLaNews);
		}catch(JDOObjectNotFoundException e){
			news = new News(nomDeLaNews,contenu);
		}
		try {
            pm.makePersistent(news);
        } finally {
            pm.close();
        }
		
		resp.sendRedirect("/panneauAdministration/modificationNews.jsp");
	}
}
